/*
 * @(#)Query.java Jan 8, 2012 - 3:43:53 PM
 * 
 * Copyright 2011 Cin/UFPE/iSPEED
 */
package speed2010.reformulacao.query;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import speed2010.reformulacao.enums.EnrichmentType;
import speed2010.reformulacao.enums.QueryMode;
import speed2010.reformulacao.enums.QueryType;
import speed2010.reformulacao.enums.TemplateType;

/**
 * @author <a href="mailto:andreza.lba@gmail.com">Andreza Leite de Alencar</a>
 */
public class Query implements Serializable {
	private static final long serialVersionUID = 3597155696147085386L;
	
	private final QueryType queryType;
	private final String originalQuery;

	private String query;
	private QueryMode queryMode;
	private TemplateType queryTemplate;
	private List<EnrichmentType> enrichmentVariables;
	

	

	private byte[] sourceOntology;
	private byte[] correspondenceOntology;
	private byte[] destinyOntology;

	private boolean usingReformulationVariables;

	public Query(final String query, List<EnrichmentType> enrichmentVariables) {
		this.query = query;
		this.originalQuery = query;
		this.enrichmentVariables = new ArrayList<EnrichmentType>();
		
		boolean containsSelect = query.toLowerCase().contains("select");
		boolean containsFrom = query.toLowerCase().contains("from");
		if (containsSelect && containsFrom) {
			this.queryType = QueryType.SPARQL;
		} else {
			this.queryType = QueryType.DL;
			this.queryTemplate = TemplateType.NONE;
		}
		
		if (enrichmentVariables == null) {
			this.enrichmentVariables = new ArrayList<EnrichmentType>();
			this.usingReformulationVariables = false;
			this.queryMode = QueryMode.RESTRICTED;
		} else {
			if (enrichmentVariables.size() > 0) {
				this.usingReformulationVariables = true;
				this.enrichmentVariables = enrichmentVariables;
				this.queryMode = QueryMode.EXPANDED;
			} else {
				this.usingReformulationVariables = false;
				this.queryMode = QueryMode.RESTRICTED;
			}
		}
	}

	/**
	 * @return Returns the query.
	 */
	public String getQuery() {
		return this.query;
	}

	/**
	 * @return Returns the originalQuery.
	 */
	public String getOriginalQuery() {
		return this.originalQuery;
	}

	/**
	 * Changes the value of query as the parameter.
	 * 
	 * @param query
	 */
	public void setQuery(final String query) {
		this.query = query;
	}

	/**
	 * @return Returns the queryMode.
	 */
	public QueryMode getQueryMode() {
		return this.queryMode;
	}

	/**
	 * @return Returns the queryType.
	 */
	public QueryType getQueryType() {
		return this.queryType;
	}

	/**
	 * @return Returns the queryTemplate.
	 */
	public TemplateType getQueryTemplate() {
		return queryTemplate;
	}

	/**
	 * Changes the value of queryTemplate as the parameter.
	 *
	 * @param queryTemplate 
	 */
	public void setQueryTemplate(TemplateType queryTemplate) {
		this.queryTemplate = queryTemplate;
	}

	/**
	 * @return Returns the sourceOntology.
	 */
	public byte[] getSourceOntology() {
		return sourceOntology;
	}

	/**
	 * Changes the value of sourceOntology as the parameter.
	 *
	 * @param sourceOntology 
	 */
	public void setSourceOntology(byte[] sourceOntology) {
		this.sourceOntology = sourceOntology;
	}

	/**
	 * @return Returns the correspondenceOntology.
	 */
	public byte[] getCorrespondenceOntology() {
		return correspondenceOntology;
	}

	/**
	 * Changes the value of correspondenceOntology as the parameter.
	 *
	 * @param correspondenceOntology 
	 */
	public void setCorrespondenceOntology(byte[] correspondenceOntology) {
		this.correspondenceOntology = correspondenceOntology;
	}

	/**
	 * @return Returns the destinyOntology.
	 */
	public byte[] getDestinyOntology() {
		return destinyOntology;
	}

	/**
	 * Changes the value of destinyOntology as the parameter.
	 *
	 * @param destinyOntology 
	 */
	public void setDestinyOntology(byte[] destinyOntology) {
		this.destinyOntology = destinyOntology;
	}

	/**
	 * @return Returns the usingReformulationVariables.
	 */
	public boolean isUsingReformulationVariables() {
		return this.usingReformulationVariables;
	}

	/**
	 * @return Returns the enrichmentVariables.
	 */
	public List<EnrichmentType> getEnrichmentVariables() {
		return this.enrichmentVariables;
	}
}
